<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>测试赛</title>
    <link rel="icon" href="img/logo.png" sizes="32x32">
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
    <style>
        html, body, #container {
            height: 100%;
            width: 100%;
        }

        .amap-icon img {
            width: 25px;
            height: 34px;
        }

        .info {
            position: relative;
            top: 0;
            right: 0;
            min-width: 0;
        }
    </style>
</head>
<body>
<div id="container"></div>

<div class="input-card">
    <h4>显示关键节点</h4>
    <input id="setFitView" type="button" class="btn" value="显示关键节点"/>
</div>
<div class="info">
    <div id="centerCoord"></div>
    <div id="tips"></div>
</div>
<script type="text/javascript"
        src="https://webapi.amap.com/maps?v=1.4.15&key=c211f8a2ee6ac8f23e228ac4d02637d4"></script>
<script type="text/javascript" src="src/poi_loc.js"></script>
<script type="text/javascript">
    var map = new AMap.Map('container', {
        resizeEnable: true,
        center: [115.846889, 40.469926],
        zoom: 13,
        mapStyle: "amap://styles/darkblue"
    });

    map.clearMap();  // 清除地图覆盖物
    var queryString = ['airport', 'station', 'hotel', 'MOC', 'venue', 'service', 'car'];

    var makersArray = [];
    for (var i = 0; i < queryString.length; i++) {
        var jo = getPOILocByType(queryString[i]);
        makersArray[i] = [];
        for (var j = 0; j < jo.length; j++) {
            var loc = new Array(); //定义一数组
            loc = jo[j]["pos"].split(","); //字符分割 
            makersArray[i].push(
                {
                    //icon:"img/airport.png",
                    position: [parseFloat(loc[0]), parseFloat(loc[1])]
                }
            );
        }
    }
    //console.log( )
    // var markers =[];
    // for(var i = 0, len = airportJson.length; i < len; i++){
    //     //console.log(airportJson[i]["name"]);

    //     var loc = new Array(); //定义一数组
    //     loc = airportJson[i]["pos"].split(","); //字符分割 
    //     markers.push(
    //         {
    //             //icon:"img/airport.png", 
    //             position: [parseFloat(loc[0]), parseFloat(loc[1])]
    //         }
    //     );
    // }

    // var markers = [{
    //     icon: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-1.png',
    //     position: [116.205467, 39.907761]
    // }, {
    //     icon: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-2.png',
    //     position: [116.368904, 39.913423]
    // }, {
    //     icon: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-3.png',
    //     position: [116.305467, 39.807761]
    // }];
    var markers = [];
    var icon = new Array();
    for (var i = 0; i < queryString.length; i++) {
        icon[i] = new AMap.Icon({
            //size: new AMap.Size(30, 30),    // 图标尺寸
            image: "img/" + queryString[i] + ".png",  // Icon的图像
            //imageOffset: new AMap.Pixel(-13, -30),  // 图像相对展示区域的偏移量，适于雪碧图等
            imageSize: new AMap.Size(20, 20)   // 根据所设置的大小拉伸或压缩图片
        });
        for (var j = 0; j < makersArray[i].length; j++) {
            makersArray[i][j] = new AMap.Marker({
                map: map,
                icon: icon[i],
                position: [makersArray[i][j].position[0], makersArray[i][j].position[1]],
                offset: new AMap.Pixel(-13, -30),
            });
            markers.push(makersArray[i][j]);
        }
    }
    // 添加一些分布不均的点到地图上,地图上添加三个点标记，作为参照


    // markers.forEach(function(marker) {
    //     new AMap.Marker({
    //         map: map,
    //         icon: icon,
    //         position: [marker.position[0], marker.position[1]],
    //         offset: new AMap.Pixel(-13, -30),
    //         // label: {
    //         //     offset: new AMap.Pixel(10, 10),  //设置文本标注偏移量
    //         //     content: "机场", //设置文本标注内容
    //         //     direction: 'right' //设置文本标注方位
    //         // }
    //     });
    // });

    var center = map.getCenter();

    // var centerText = '当前中心点坐标：' + center.getLng() + ',' + center.getLat();
    // document.getElementById('centerCoord').innerHTML = centerText;
    // document.getElementById('tips').innerHTML = '成功添加三个点标记，其中有两个在当前地图视野外！';

    // 添加事件监听, 使地图自适应显示到合适的范围
    AMap.event.addDomListener(document.getElementById('setFitView'), 'click', function () {
        var newCenter = map.setFitView();
    });
</script>
</body>
</html>